package org.jeecg.modules.veterans.controller;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.GlobalConstants;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.ImportExcelUtil;
import org.jeecg.common.util.RestUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.util.SecurityUtil;
import org.jeecg.modules.veterans.entity.*;
import org.jeecg.modules.veterans.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.system.service.ISysDictService;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 优待服务信息表
 * @Author: jeecg-boot
 * @Date:   2022-03-30
 * @Version: V1.0
 */
@Api(tags="优待服务信息表")
@RestController
@RequestMapping("/discount/sysService")
@Slf4j
public class SysServiceController extends JeecgController<SysService, ISysServiceService> {
	@Autowired
	private ISysServiceService sysServiceService;
	 @Autowired
	 private ISysServiceAppService sysServiceAppService;
	@Autowired
	private ISysDictService dictService;
	@Autowired
	public ISysCollectRecordService sysCollectRecordService;

	@Autowired
	private ISysServiceDiscountService discountService;
	@Autowired
	private ISysServicePriorityService priorityService;


	 /**
	  * 分页列表查询(列表)
	  *
	  * @param sysService
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 //@AutoLog(value = "优待服务信息表-分页列表查询")
	 @RequiresPermissions("service:view")
	 @ApiOperation(value="优待服务信息表-分页列表查询", notes="优待服务信息表-分页列表查询")
	 @GetMapping(value = "/list")
	 public Result<IPage<SysService>> queryPageList(SysService sysService,
													@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
													@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
													HttpServletRequest req) {
		 QueryWrapper<SysService> queryWrapper = QueryGenerator.initQueryWrapper(sysService, req.getParameterMap());
		 LoginUser loginUser = SecurityUtil.getLoginUser();
		 String dep = loginUser.getOrgCode();
		 switch (dep){
			 case "A02A02":
				 queryWrapper.eq("area","1");
				 break;
			 case "A02A01":
				 queryWrapper.eq("area","2");
				 break;
			 case "A02A03":
				 queryWrapper.eq("area","3");
				 break;
			 case "A02A04":
				 queryWrapper.eq("area","4");
				 break;
			 case "A02A05":
				 queryWrapper.eq("area","5");
				 break;
			 case "A02A07":
				 queryWrapper.eq("area","6");
				 break;
			 case "A02A08":
				 queryWrapper.eq("area","7");
				 break;
			 case "A02A09":
				 queryWrapper.eq("area","8");
				 break;
			 case "A02A10":
				 queryWrapper.eq("area","9");
				 break;
		 }
		 queryWrapper.eq("state","1");
		 Page<SysService> page = new Page<SysService>(pageNo, pageSize);
		 IPage<SysService> pageList = sysServiceService.page(page, queryWrapper);
		 return Result.OK(pageList);
	 }
	 //@AutoLog(value = "优待服务信息表-分页列表查询")
	 @ApiOperation(value="优待服务信息表-分页列表查询", notes="优待服务信息表-分页列表查询")
	 @GetMapping(value = "/applist")
	 public Result<IPage<SysServiceApp>> appqueryPageList(SysServiceApp sysService,
													@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
													@RequestParam(name="pageSize", defaultValue="1000") Integer pageSize,
													HttpServletRequest req) {
		 QueryWrapper<SysServiceApp> queryWrapper = QueryGenerator.initQueryWrapper(sysService, req.getParameterMap());
		 queryWrapper.eq("state","1");
//		 queryWrapper.eq("service_type","1");
		 Page<SysServiceApp> page = new Page<SysServiceApp>(pageNo, pageSize);
		 IPage<SysServiceApp> pageList = sysServiceAppService.page(page, queryWrapper);
		 return Result.OK(pageList);
	 }

	 @ApiOperation(value="按区域查询优待服务总数", notes="按区域查询优待服务总数")
	 @GetMapping(value = "/mountByArea")
	 public Result<Map> mountByArea(SysService sysService) {
	 	 Map<String,Object> map = new HashMap<>();
		 QueryWrapper<SysService> queryWrapper = new QueryWrapper<>();
		 //宿城区
		 map.put("sc",sysServiceAppService.queryServiceMountByArea(1));
		 //宿豫区
		 map.put("sy",sysServiceAppService.queryServiceMountByArea(2));
		 //沭阳县
		 map.put("shy",sysServiceAppService.queryServiceMountByArea(3));
		 //泗阳县
		 map.put("siy",sysServiceAppService.queryServiceMountByArea(4));
		 //泗洪县
		 map.put("sh",sysServiceAppService.queryServiceMountByArea(5));
		 //经开区
		 map.put("jk",sysServiceAppService.queryServiceMountByArea(6));
		 //湖滨新区
		 map.put("hb",sysServiceAppService.queryServiceMountByArea(7));
		 //洋河新区
		 map.put("yh",sysServiceAppService.queryServiceMountByArea(8));
		 //苏宿园区
		 map.put("ss",sysServiceAppService.queryServiceMountByArea(9));

		 return Result.OK(map);
	 }

	 @ApiOperation(value="按区域查询优待服务总数", notes="按区域查询优待服务总数")
	 @GetMapping(value = "/mountByAreaAndServiceType")
	 public Result<Map> mountByAreaAndServiceType(SysService sysService) {
		 Map<String,Object> map = new HashMap<>();
		 QueryWrapper<SysService> queryWrapper = new QueryWrapper<>();
		 //宿城区
		 map.put("sc",sysServiceAppService.queryServiceMountByAreaAndServiceType(1,sysService.getServiceType()));
		 //宿豫区
		 map.put("sy",sysServiceAppService.queryServiceMountByAreaAndServiceType(2,sysService.getServiceType()));
		 //沭阳县
		 map.put("shy",sysServiceAppService.queryServiceMountByAreaAndServiceType(3,sysService.getServiceType()));
		 //泗阳县
		 map.put("siy",sysServiceAppService.queryServiceMountByAreaAndServiceType(4,sysService.getServiceType()));
		 //泗洪县
		 map.put("sh",sysServiceAppService.queryServiceMountByAreaAndServiceType(5,sysService.getServiceType()));
		 //经开区
		 map.put("jk",sysServiceAppService.queryServiceMountByAreaAndServiceType(6,sysService.getServiceType()));
		 //湖滨新区
		 map.put("hb",sysServiceAppService.queryServiceMountByAreaAndServiceType(7,sysService.getServiceType()));
		 //洋河新区
		 map.put("yh",sysServiceAppService.queryServiceMountByAreaAndServiceType(8,sysService.getServiceType()));
		 //苏宿园区
		 map.put("ss",sysServiceAppService.queryServiceMountByAreaAndServiceType(9,sysService.getServiceType()));

		 return Result.OK(map);
	 }

	 /**
	  * 分页列表查询（审核列表）
	  *
	  * @param sysService
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 //@AutoLog(value = "优待服务信息表-分页列表查询")
	 @RequiresPermissions("service:view")
	 @ApiOperation(value="优待服务信息表-分页列表查询", notes="优待服务信息表-分页列表查询")
	 @GetMapping(value = "/listSh")
	 public Result<IPage<SysService>> queryPageListSh(SysService sysService,
													@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
													@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
													HttpServletRequest req) {
		 QueryWrapper<SysService> queryWrapper = QueryGenerator.initQueryWrapper(sysService, req.getParameterMap());
		 LoginUser loginUser = SecurityUtil.getLoginUser();
		 String dep = loginUser.getOrgCode();
		 switch (dep){
			 case "A02A02":
				 queryWrapper.eq("area","1");
				 break;
			 case "A02A01":
				 queryWrapper.eq("area","2");
				 break;
			 case "A02A03":
				 queryWrapper.eq("area","3");
				 break;
			 case "A02A04":
				 queryWrapper.eq("area","4");
				 break;
			 case "A02A05":
				 queryWrapper.eq("area","5");
				 break;
			 case "A02A07":
				 queryWrapper.eq("area","6");
				 break;
			 case "A02A08":
				 queryWrapper.eq("area","7");
				 break;
			 case "A02A09":
				 queryWrapper.eq("area","8");
				 break;
			 case "A02A10":
				 queryWrapper.eq("area","9");
				 break;
		 }
		 queryWrapper.eq("state","2");
		 Page<SysService> page = new Page<SysService>(pageNo, pageSize);
		 IPage<SysService> pageList = sysServiceService.page(page, queryWrapper);
		 return Result.OK(pageList);
	 }

	 /**
	  * 分页列表查询(列表)
	  *
	  * @param sysService
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 //@AutoLog(value = "优待服务信息表-分页列表查询")
	 @RequiresPermissions("service:view")
	 @ApiOperation(value="优待服务信息表-分页列表查询", notes="优待服务信息表-分页列表查询")
	 @GetMapping(value = "/collect")
	 public Result<IPage<SysService>> queryCollectList(SysService sysService,
							@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
							@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
							HttpServletRequest req) {
		 LoginUser loginUser = SecurityUtil.getLoginUser();
		 String u = loginUser.getId();
		 QueryWrapper<SysCollectRecord> queryWrappercollect = new QueryWrapper<>();
		 queryWrappercollect.eq("user_id",u);
		 queryWrappercollect.eq("type","2");
		 List<SysCollectRecord> list = sysCollectRecordService.list(queryWrappercollect);
		 List <String> CllectList = new ArrayList<>();
		 for(int i=0;i < list.size(); i++){
			 CllectList.add(list.get(i).getRecordId());
		 }
		 QueryWrapper<SysService> queryWrapper = new QueryWrapper<>();
		 queryWrapper.eq("state","1");
		 queryWrapper.in("id",CllectList);
		 Page<SysService> page = new Page<SysService>(pageNo, pageSize);
		 IPage<SysService> pageList = sysServiceService.page(page, queryWrapper);
		 List<SysService> mlist = pageList.getRecords();
		 for (SysService item:mlist) {
			 item.setArea(dictService.queryDictTextByKey("sys_area",item.getArea()));
			 item.setServiceType(dictService.queryDictTextByKey("service_type",item.getServiceType()));
		 }
		 return Result.OK(pageList);
	 }

	/**
	 * app分页列表查询
	 *
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "app优待服务信息表-分页列表查询")
	@ApiOperation(value="优待服务信息表-分页列表查询", notes="优待服务信息表-分页列表查询")
	@GetMapping(value = "/mDiscount")
	public Result<IPage<SysServiceApp>> mqueryPageList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
									@RequestParam(name="lng") double lng,
									@RequestParam(name="lat") double lat,
									@RequestParam(name="distance") String distance,
									@RequestParam(name="area") String area,
									@RequestParam(name="type") String type,
									@RequestParam(name="sort") String sort,
									@RequestParam(name="searchCon") String searchCon,
								   HttpServletRequest req) {
		Page<SysServiceApp> page = new Page<SysServiceApp>(pageNo, pageSize);
		page = sysServiceAppService.queryDiscountListByCircle(page,lng,lat,distance,area,type,sort,searchCon);
		List<SysServiceApp> list = page.getRecords();
		for (SysServiceApp item:list) {
			item.setArea(dictService.queryDictTextByKey("sys_area",item.getArea()));
			item.setServiceType(dictService.queryDictTextByKey("service_type",item.getServiceType()));
		}
		return Result.OK(page);
	}

	 /**
	  * app分页列表查询
	  *
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 //@AutoLog(value = "app优待服务信息表-分页列表查询")
	 @ApiOperation(value="优待服务信息表-分页列表查询", notes="优待服务信息表-分页列表查询")
	 @GetMapping(value = "/mService")
	 public Result<IPage<SysServiceApp>> mdiscountlist(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
													 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
													 @RequestParam(name="lng") double lng,
													 @RequestParam(name="lat") double lat,
													 @RequestParam(name="distance") String distance,
													 @RequestParam(name="area") String area,
													 @RequestParam(name="sort") String sort,
													@RequestParam(name="serviceType") String serviceType,
													 HttpServletRequest req) {
		 Page<SysServiceApp> page = new Page<SysServiceApp>(pageNo, pageSize);
		 page = sysServiceAppService.queryServiceListByCircle(page,lng,lat,distance,area,sort,serviceType);
		 List<SysServiceApp> list = page.getRecords();
		 for (SysServiceApp item:list) {
			 item.setArea(dictService.queryDictTextByKey("sys_area",item.getArea()));
			 item.setServiceType(dictService.queryDictTextByKey("service_type",item.getServiceType()));
		 }
		 return Result.OK(page);
	 }

	/**
	 *   添加
	 *
	 * @param sysService
	 * @return
	 */
	@RequiresPermissions("service:view")
	@AutoLog(value = "优待服务信息表-添加")
	@ApiOperation(value="优待服务信息表-添加", notes="优待服务信息表-添加")
	@PostMapping(value = "/add")
	@Transactional(rollbackFor = Exception.class)
	public Result<String> add(@RequestBody SysService sysService) {
		//获取经纬度信息
		Map<String,Object> map = new HashMap<>();
		map.put("address",sysService.getAddress());
		map.put("region", GlobalConstants.MAP_QQ_REGION);
		map.put("key",GlobalConstants.MAP_QQ_KEY);
		JSONObject request = new JSONObject(map);
		JSONObject jsonObject = RestUtil.get(GlobalConstants.MAP_QQ_URL,request);
		if(0 != jsonObject.getInteger("status")) return Result.error("请填写正确地址！");
		sysService.setLat(jsonObject.getJSONObject("result").getJSONObject("location").getBigDecimal("lat"));
		sysService.setLng(jsonObject.getJSONObject("result").getJSONObject("location").getBigDecimal("lng"));
		sysServiceService.save(sysService);
		if(sysService.getDiscounts() != null && sysService.getDiscounts().size()>0){
			for (SysServiceDiscount item:sysService.getDiscounts()) {
				item.setServiceId(sysService.getId());
			}
			discountService.saveBatch(sysService.getDiscounts());
		}
		if(sysService.getPriorities() != null && sysService.getPriorities().size()>0){
			for (SysServicePriority item:sysService.getPriorities()) {
				item.setServiceId(sysService.getId());
			}
			priorityService.saveBatch(sysService.getPriorities());
		}
		return Result.OK("添加成功！");
	}

	 /**
	  *   添加
	  *
	  * @param sysService
	  * @return
	  */
	 @AutoLog(value = "优待服务信息表-添加")
	 @ApiOperation(value="优待服务信息表-添加", notes="优待服务信息表-添加")
	 @PostMapping(value = "/apply")
	 @Transactional(rollbackFor = Exception.class)
	 public Result<String> apply(@RequestBody SysService sysService) {
		 //获取经纬度信息
		 Map<String,Object> map = new HashMap<>();
		 map.put("address",sysService.getAddress());
		 map.put("region", GlobalConstants.MAP_QQ_REGION);
		 map.put("key",GlobalConstants.MAP_QQ_KEY);
		 JSONObject request = new JSONObject(map);
		 JSONObject jsonObject = RestUtil.get(GlobalConstants.MAP_QQ_URL,request);
		 if(0 != jsonObject.getInteger("status")){
		 	return Result.error("请填写正确地址！");
		 }else{
			 sysService.setLat(jsonObject.getJSONObject("result").getJSONObject("location").getBigDecimal("lat"));
			 sysService.setLng(jsonObject.getJSONObject("result").getJSONObject("location").getBigDecimal("lng"));
			 sysService.setState("2");
			 sysService.setStars("0");
			 sysServiceService.save(sysService);
			 if(sysService.getDiscounts() != null && sysService.getDiscounts().size()>0){
				 for (SysServiceDiscount item:sysService.getDiscounts()) {
					 item.setServiceId(sysService.getId());
				 }
				 discountService.saveBatch(sysService.getDiscounts());
			 }
			 if(sysService.getPriorities() != null && sysService.getPriorities().size()>0){
				 for (SysServicePriority item:sysService.getPriorities()) {
					 item.setServiceId(sysService.getId());
				 }
				 priorityService.saveBatch(sysService.getPriorities());
			 }
			 return Result.OK("添加成功！");
		 }
	 }

	 /**
	  *   地址检查
	  *
	  * @param address
	  * @return
	  */
	 @AutoLog(value = "优待服务信息表-地址检查")
	 @ApiOperation(value="优待服务信息表-地址检查", notes="优待服务信息表-地址检查")
	 @GetMapping(value = "/checkAddress")
	 public Result<String> checkAddress(@RequestParam("address") String address) {
		 //获取经纬度信息
		 Map<String,Object> map = new HashMap<>();
		 map.put("address",address);
		 map.put("region", GlobalConstants.MAP_QQ_REGION);
		 map.put("key",GlobalConstants.MAP_QQ_KEY);
		 JSONObject request = new JSONObject(map);
		 JSONObject jsonObject = RestUtil.get(GlobalConstants.MAP_QQ_URL,request);
		 if(0 != jsonObject.getInteger("status")){
			 return Result.error("请填写正确地址！");
		 }else{
			 return Result.OK("地址格式正确！");
		 }
	 }

	 /**
	  *   现场核验
	  *
	  * @param sysService
	  * @return
	  */
	 @AutoLog(value = "优待服务信息表-现场核验")
	 @ApiOperation(value="优待服务信息表-现场核验", notes="优待服务信息表-现场核验")
	 @PostMapping(value = "/check")
	 public Result<String> check(@RequestBody SysService sysService) {
		 sysService.setChecker(SecurityUtil.getLoginUser().getRealname());
		 sysService.setCheckTime(new Date());
		 sysServiceService.updateById(sysService);
		 return Result.OK("核验成功！");
	 }

	/**
	 *  编辑
	 *
	 * @param sysService
	 * @return
	 */
	@RequiresPermissions("service:view")
	@AutoLog(value = "优待服务信息表-编辑")
	@ApiOperation(value="优待服务信息表-编辑", notes="优待服务信息表-编辑")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	@Transactional(rollbackFor = Exception.class)
	public Result<String> edit(@RequestBody SysService sysService) {
		//获取经纬度信息
		Map<String,Object> map = new HashMap<>();
		map.put("address",sysService.getAddress());
		map.put("region", GlobalConstants.MAP_QQ_REGION);
		map.put("key",GlobalConstants.MAP_QQ_KEY);
		JSONObject request = new JSONObject(map);
		JSONObject jsonObject = RestUtil.get(GlobalConstants.MAP_QQ_URL,request);
		if(0 != jsonObject.getInteger("status"))return Result.error("请填写正确地址！");
		sysService.setLat(jsonObject.getJSONObject("result").getJSONObject("location").getBigDecimal("lat"));
		sysService.setLng(jsonObject.getJSONObject("result").getJSONObject("location").getBigDecimal("lng"));
		sysServiceService.updateById(sysService);
		//delete first
		discountService.deleteBatchByServiceId(sysService.getId());
		priorityService.deleteBatchByServiceId(sysService.getId());
		if(sysService.getDiscounts() != null && sysService.getDiscounts().size()>0){
			for (SysServiceDiscount item:sysService.getDiscounts()) {
				item.setServiceId(sysService.getId());
			}
			discountService.saveBatch(sysService.getDiscounts());
		}
		if(sysService.getPriorities() != null && sysService.getPriorities().size()>0){
			for (SysServicePriority item:sysService.getPriorities()) {
				item.setServiceId(sysService.getId());
			}
			priorityService.saveBatch(sysService.getPriorities());
		}
		return Result.OK("编辑成功!");
	}

	 /**
	  *  编辑
	  *
	  * @param sysService
	  * @return
	  */
	 @AutoLog(value = "优待服务信息表-点赞更新")
	 @ApiOperation(value="优待服务信息表-点赞更新", notes="优待服务信息表-点赞更新")
	 @RequestMapping(value = "/updatenum", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<String> updatenum(@RequestBody SysService sysService) {
//		 sysService.setLikeNum("1");
		 sysServiceService.updateById(sysService);
		 return Result.OK("编辑成功!");
	 }


	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@RequiresPermissions("service:view")
	@AutoLog(value = "优待服务信息表-通过id删除")
	@ApiOperation(value="优待服务信息表-通过id删除", notes="优待服务信息表-通过id删除")
	@DeleteMapping(value = "/delete")
	@Transactional(rollbackFor = Exception.class)
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		sysServiceService.removeById(id);
		discountService.deleteBatchByServiceId(id);
		priorityService.deleteBatchByServiceId(id);
		//delete first
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@RequiresPermissions("service:view")
	@AutoLog(value = "优待服务信息表-批量删除")
	@ApiOperation(value="优待服务信息表-批量删除", notes="优待服务信息表-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.sysServiceService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */

	//@AutoLog(value = "优待服务信息表-通过id查询")
	@ApiOperation(value="优待服务信息表-通过id查询", notes="优待服务信息表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<SysService> queryById(@RequestParam(name="id",required=true) String id) {
		SysService sysService = sysServiceService.getInfoById(id);
		if(sysService==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(sysService);
	}

	 @Value("${jeecg.path.upload}")
	 private String upLoadPath;

    /**
    * 导出excel
    *
    * @param request
    * @param sysService
    */
	@RequiresPermissions("service:view")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, SysService sysService) {
		QueryWrapper<SysService> queryWrapper = QueryGenerator.initQueryWrapper(sysService, request.getParameterMap());
		LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

		// Step.2 获取导出数据
		List<SysService> pageList = service.list(queryWrapper);
		List<SysService> serviceList = null;
		List<SysServiceDiscount> discountList = new ArrayList<>();
		List<SysServicePriority> priorityList = new ArrayList<>();
		// Step.3 多sheet处理
		List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
		// 过滤选中数据
		String selections = request.getParameter("selections");
		if (oConvertUtils.isNotEmpty(selections)) {
			List<String> selectionList = Arrays.asList(selections.split(","));
			serviceList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
		} else {
			serviceList = pageList;
		}
		for (SysService item :serviceList) {
			QueryWrapper<SysServiceDiscount> wrapper = new QueryWrapper<>();
			wrapper.eq("service_id",item.getId());
			List<SysServiceDiscount> discounts = discountService.list(wrapper);
			for (SysServiceDiscount discount:discounts) {
				discount.setServiceName(item.getName());
			}
			discountList.addAll(discounts);
			QueryWrapper<SysServicePriority> wrapper1 = new QueryWrapper<>();
			wrapper1.eq("service_id",item.getId());
			List<SysServicePriority> priorities = priorityService.list(wrapper1);
			for (SysServicePriority priority:priorities) {
				priority.setServiceName(item.getName());
			}
			priorityList.addAll(priorities);
		}
		Map<String, Object> map = new HashMap<>(5);
		ExportParams  exportParams=new ExportParams( "优待服务信息表", "导出人:" + sysUser.getRealname(), "优待服务信息表",upLoadPath);
		exportParams.setType(ExcelType.XSSF);
		//map.put("title",exportParams);
		//表格Title
		map.put(NormalExcelConstants.PARAMS,exportParams);
		//表格对应实体
		map.put(NormalExcelConstants.CLASS,SysService.class);
		//数据集合
		map.put(NormalExcelConstants.DATA_LIST, serviceList);
		listMap.add(map);

		Map<String, Object> mapDiscount = new HashMap<>(5);
		ExportParams  exportParamsDiscount =new ExportParams( "优惠项目表",  "导出人:" + sysUser.getRealname(),"优惠项目表");
		exportParamsDiscount.setType(ExcelType.XSSF);
		//map.put("title",exportParams);
		//表格Title
		mapDiscount.put(NormalExcelConstants.PARAMS,exportParamsDiscount);
		//表格对应实体
		mapDiscount.put(NormalExcelConstants.CLASS,SysServiceDiscount.class);
		//数据集合
		mapDiscount.put(NormalExcelConstants.DATA_LIST, discountList);
		listMap.add(mapDiscount);

		Map<String, Object> mapPriority = new HashMap<>(5);
		ExportParams  exportParamsPriority =new ExportParams( "优先项目表", "导出人:" + sysUser.getRealname(), "优先项目表");
		exportParamsPriority.setType(ExcelType.XSSF);
		//map.put("title",exportParams);
		//表格Title
		mapPriority.put(NormalExcelConstants.PARAMS,exportParamsPriority);
		//表格对应实体
		mapPriority.put(NormalExcelConstants.CLASS,SysServicePriority.class);
		//数据集合
		mapPriority.put(NormalExcelConstants.DATA_LIST, priorityList);
		listMap.add(mapPriority);



		// Step.4 AutoPoi 导出Excel
		ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
		//此处设置的filename无效 ,前端会重更新设置一下
		mv.addObject(NormalExcelConstants.FILE_NAME, "优待服务信息表");
		mv.addObject(NormalExcelConstants.MAP_LIST, listMap);


        return mv;
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException {
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		// 错误信息
		List<String> errorMessage = new ArrayList<>();
		int successLines = 0, errorLines = 0;
		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			MultipartFile file = entity.getValue();// 获取上传文件对象
			ImportParams params = new ImportParams();
			params.setTitleRows(2);
			params.setHeadRows(1);
			params.setNeedSave(true);
			try {
				List<SysService> listService = ExcelImportUtil.importExcel(file.getInputStream(), SysService.class, params);
				List<SysServiceDiscount> listDiscount = ExcelImportUtil.importExcel(file.getInputStream(), SysServiceDiscount.class, params);
				List<SysServicePriority> listPriority = ExcelImportUtil.importExcel(file.getInputStream(), SysServicePriority.class, params);
				for (int i = 0; i < listService.size(); i++) {
					SysService serviceExcel = listService.get(i);

				}
			} catch (Exception e) {
//			  errorMessage.add("发生异常：" + e.getMessage());
				log.error(e.getMessage(), e);
			} finally {
				try {
					file.getInputStream().close();
				} catch (IOException e) {
					log.error(e.getMessage(), e);
				}
			}
		}
		return ImportExcelUtil.imporReturnRes(errorLines,successLines,errorMessage);
    }

}
